package org.example;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class CozeAgentCaller {
    private static final String API_KEY = "pat_cYF2Ud8r0MZeUayT1jSjU7gpuIX7PjgGyCFikTQa46HCO12y4BnQrYGUFFMZOwLa";
    private static final String API_URL = "https://www.coze.cn/space/7494493821301112884/bot/7496420663788961827";

    public static void main(String[] args) {
        try {
            // 创建HttpClient实例
            HttpClient httpClient = HttpClients.createDefault();
            // 创建HttpPost请求
            HttpPost httpPost = new HttpPost(API_URL);

            // 设置请求头
            httpPost.setHeader("Authorization", "Bearer " + API_KEY);
            httpPost.setHeader("Content-Type", "application/json");

            // 请求体
            String requestBody = "{\"input\": \"你的输入内容\"}";
            StringEntity entity = new StringEntity(requestBody);
            httpPost.setEntity(entity);

            // 执行请求
            HttpResponse response = httpClient.execute(httpPost);

            // 获取响应状态码
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == 200) {
                // 获取响应内容
                String responseBody = EntityUtils.toString(response.getEntity());
                System.out.println("响应内容: " + responseBody);
            } else {
                System.out.println("请求失败，状态码: " + statusCode);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}